<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>服务监控</title>
</head>
<body>


<button id="refreshServiceStatus">刷新后端服务状态</button>

<table border="2px" style="white-space:nowrap;" >
    <thead>
        <tr>
            <td>序号</td>
            <td>服务名称</td>
            <td>状态</td>
            <td>返回值</td>
        </tr>
    </thead>
    <tbody id="serviceStatusBody">

    </tbody>
</table>


</body>
<script src="http://libs.baidu.com/jquery/1.8.0/jquery.min.js"></script>
<script type="text/javascript">

    var serverHost = "";
    $(function () {


        $("#refreshServiceStatus").bind("click",refreshServiceStatus());


        function refreshServiceStatus() {

            var serviceArray = ["todo","authorization","metadata","org","common","integrate","designmodel","operationadmin","flowdesign","metadataruntime","file","permission","syspermission","integratedesign"]

            $("#serviceStatusBody").empty();
            var html = "";

            var i = 1;
            $.each(serviceArray,function(index,value){
                var serviceStatus = "DOWN";

                $.ajax({
                    url:serverHost+"/api/"+value+"/echo?requestId=xxx",

                    success: function(data,status) {

                        var errorMsg = "";
                        if (data.success == true){
                            serviceStatus = "UP";
                        }else{
                            errorMsg = data.errMessage;
                        }
                        console.log(value + " 返回状态：" + JSON.stringify( data) )



                        $("#serviceStatusBody").append("<tr><td>"+
                            (i++)+"</td><td>"+
                            "app-"+value+"</td><td>"+
                            serviceStatus+"</td><td>"+errorMsg+
                            "</td></tr>");

                },
                error:function(res){
                    console.log(value + " 返回结果：" + JSON.stringify( res) )

                    if (res.status == 200){
                        serviceStatus = "UP";
                    }

                    $("#serviceStatusBody").append("<tr><td>"+
                        (i++)+"</td><td>"+
                        "app-"+value+"</td><td>"+
                        serviceStatus+"</td><td>"+JSON.stringify( res)+
                        "</td></tr>");
                }});

                console.log( value+"服务状态是：" + serviceStatus)
            });


        }

    });


</script>
</html>